package cn.zcy.controller.downloadandupload;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.lang.reflect.Method;

/**
 * 文件上传
 */
@Controller
public class UploadController {
    @RequestMapping(value = "upload",method = RequestMethod.POST)
    public String upload(HttpServletRequest request,String desc, MultipartFile[] myfile) throws Exception{
        for (MultipartFile multipartFile:myfile){
            System.out.println(desc);
            System.out.println(multipartFile.getOriginalFilename());
            String path  =request.getServletContext().getRealPath("/")+multipartFile.getOriginalFilename();
            System.out.println("path = " + path);
            //根据路径分装成文件对象
            File file =new File(path);
            //上传文件到路径
            multipartFile.transferTo(file);
        }
        return "sucess";
    }
}
